package com.example.myweather.widget;

import com.example.myweather.R;
import com.example.myweather.listener.CancelButtonConfigurationWidgetActivity;
import com.example.myweather.listener.OKButtonConfigurationWidgetActivity;
import com.example.myweather.modelo.Weather;
import com.example.myweather.modelo.WeatherWebService;
import com.example.myweather.modelo.WebServicesXDotNet;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RemoteViews;
import android.widget.Spinner;

public class WidgetConfigurationActivity extends Activity{
	
	private int widgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
	
	private Button configButtonOK;
	private Button configButtonCancel;	
	private EditText cityName;
	private Spinner countryName;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setResult(RESULT_CANCELED);
		
		setContentView(R.layout.widget_configuration_activity);
		
		this.configButtonOK = (Button)findViewById(R.id.ok_configuration);
		
		this.configButtonCancel = (Button)findViewById(R.id.cancel_configuration);
		
		this.cityName = (EditText)findViewById(R.id.input_city_name);
		
		this.countryName = (Spinner)findViewById(R.id.input_country_name);
		
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.country_array,  android.R.layout.simple_spinner_item);
		
		//Specify the layout to use when the list of choices appears
		
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		this.countryName.setAdapter(adapter);
		
	    this.configButtonOK.setOnClickListener(new OKButtonConfigurationWidgetActivity(this));
		
	    this.configButtonCancel.setOnClickListener(new CancelButtonConfigurationWidgetActivity(this));
	    
		Intent intent = getIntent();
		Bundle extras = intent.getExtras();
		if (extras != null) {
		    this.widgetId = extras.getInt(
		            AppWidgetManager.EXTRA_APPWIDGET_ID, 
		            AppWidgetManager.INVALID_APPWIDGET_ID);
		}
		
		// If gave us an intent without the widget id, just finish.
	    if (this.widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
	         finish();
	    }
		
		
	}
	
	
	public int getWidgetId(){
		return this.widgetId;
	}
	
	public String getInputCityName(){
		return this.cityName.getText().toString();
	}
	
	public String getInputCountryName(){
		return this.countryName.getSelectedItem().toString();
	}
	
	
}
